package com.xh.audit.controller.project;

import com.xh.audit.entity.project.AuditNotice;
import com.xh.audit.service.AuditNoticeService;
import com.xh.common.R;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * 审计通知 前端控制器
 * </p>
 *
 * @author lhl
 * @since 2023-10-19
 */
@RestController
@RequestMapping("/audit-notice")
@RequiredArgsConstructor
@Validated
public class AuditNoticeController {

    private final AuditNoticeService auditNoticeService;

    @PostMapping("/save")
    public R<AuditNotice> save(@RequestBody
                               @Validated
                                       AuditNotice law) {
        boolean saveFlag = auditNoticeService.saveOrUpdate(law);

        if (saveFlag) {
            return R.success(law);
        }
        return R.failed("保存失败");
    }


    @PostMapping("/info/{id}")
    public R<AuditNotice> info(@PathVariable
                               @Validated
                               @NotNull(message = "id不能空")
                                       Integer id) {

        AuditNotice byId = auditNoticeService.getById(id);
        return R.success(byId);
    }

}
